{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import casefoam \n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import holoviews as hv\n",
    "hv.extension('bokeh') #, 'matplotlib')\n",
    "#caseStructure = [['grid1', 'grid2', 'grid3']]\n",
    "caseStructure = [['height_02', 'height_03', 'height_04'],\n",
    "                 ['grid1', 'grid2', 'grid3']]\n",
    "baseCase = 'Cases'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# load probe data\n",
    "probeDir = 'probes/0'\n",
    "p = casefoam.time_series(probeDir, 'p', caseStructure, baseCase)\n",
    "T = casefoam.time_series(probeDir, 'T', caseStructure, baseCase)\n",
    "U = casefoam.time_series(probeDir, 'U', caseStructure, baseCase)\n",
    "U.columns = ['Ux','Uy','Uz','col_height','res']\n",
    "U.reset_index('t',inplace=True)\n",
    "U_ds = hv.Dataset(U, [ 'col_height','res'], ['t','Ux','Uy','Uz'])\n",
    "p.columns = ['p','col_height','res']\n",
    "p.reset_index('t',inplace=True)\n",
    "p_ds = hv.Dataset(p, [ 'col_height','res'], ['t','p'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Curve [width=600,height=600]\n",
    "#ds.to(hv.Curve, 't', 'Ux')\n",
    "p_ds.to(hv.Curve,'t','p').overlay('res')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "force_dir = 'forces/0'\n",
    "force_file = 'force.dat'\n",
    "force = casefoam.time_series(force_dir,force_file,caseStructure,baseCase)\n",
    "force.reset_index('t',inplace=True)\n",
    "force.drop(columns=[4,5,6,7,8,9],inplace=True)\n",
    "force.columns = ['t','Fx','Fy','Fz','col_height','res']\n",
    "Force_ds = hv.Dataset(force, [ 'col_height','res'], ['t','Fx','Fy','Fz'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "%%opts Curve [width=600,height=600]\n",
    "#ds.to(hv.Curve, 't', 'Ux')\n",
    "Force_ds.to(hv.Curve,'t','Fx').overlay('res')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "setDir = 'sample1'\n",
    "sets = casefoam.positional_field(setDir,'centreLine_T.xy',0.2,caseStructure,baseCase)\n",
    "sets.columns = ['x','T','col_height','res']\n",
    "sets_ds = hv.Dataset(sets, [ 'col_height','res'], ['x','T'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sets.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Curve [width=600,height=600]\n",
    "#ds.to(hv.Curve, 't', 'Ux')\n",
    "sets_ds.to(hv.Curve,'x','T').overlay('res')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "surfaceDir = 'freeSurface'\n",
    "surface = casefoam.positional_field(surfaceDir,'U_freeSurface.raw',0.3,caseStructure,baseCase)\n",
    "surface.columns = ['x','y','z','Ux','Uy','Uz','col_height','res']\n",
    "surface_ds = hv.Dataset(surface, [ 'col_height','res'], ['x','y','z','Ux','Uy','Uz'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Scatter [width=600,height=600]\n",
    "%%opts Scatter (muted_alpha=0.0)\n",
    "#ds.to(hv.Curve, 't', 'Ux')\n",
    "surface_ds.to(hv.Scatter,'x','y').overlay('res')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "func = casefoam.postFunctions.getFreeSurfaceWallAndCentre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "surfaceDir = 'freeSurface'\n",
    "surface = casefoam.posField_to_timeSeries(surfaceDir,'U_freeSurface.raw',func,caseStructure,baseCase)\n",
    "surface.columns = ['min','mean','max','col_height','res']\n",
    "surface.reset_index(inplace=True)\n",
    "surface_ds = hv.Dataset(surface, [ 'col_height','res'], ['time','min','mean','max'])\n",
    "surface.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Scatter [width=600,height=600]\n",
    "%%opts Scatter (muted_alpha=0.0)\n",
    "#ds.to(hv.Curve, 't', 'Ux')\n",
    "surface_ds.to(hv.Scatter,'time','max').overlay('col_height')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
